/**
 * =====================================================================================
 *       @file  ngx_shmem.c
 *      @brief  
 *
 *  Detailed description starts here.
 *
 *   @internal
 *     Created  2012年05月11日 10时00分25秒 
 *    Revision  1.0.0.0
 *    Compiler  gcc/g++
 *
 *     @author  luis
 * =====================================================================================
 */

#include <sys/mman.h>
#include "ngx_shmem.h"

ngx_int_t ngx_shm_alloc(ngx_shm_t *shm)
{
    shm->addr = (u_char  *)mmap(NULL, shm->size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
    
    if (shm->addr == MAP_FAILED)
    {
        perror("mmap"); 
        return NGX_ERROR;
    }

    return NGX_OK;
}

void ngx_shm_freee(ngx_shm_t *shm)
{
    if (munmap((void *)shm->addr, shm->size) == -1)
    {
        perror("munmap");
    }
}
